/*
 * FNISVGEditor - JavaScript - based editor for SVG graphics 
 * Copyright (C) 2008 - 2009 Antti Leppä / Foyt
 * http://www.foyt.fi
 * 
 * License: 
 * 
 * Licensed under GNU Lesser General Public License Version 2.1 or later (the "LGPL") 
 * http://www.gnu.org/licenses/lgpl.html
 */
FNISVGEditorView = Class.create(GUIComponent, {
  initialize: function($super, editorInstance) {
    $super({});    
    this.domNode = new Element("div", {
      className: "fniSVGEditorView"
    });
    this.domNode.appendChild(editorInstance.getSVGDocument().getRootElement());
    
    this._mouseout = false;
    
    this._mouseOverDomNodeListener = this._onMouseOverDomNode.bindAsEventListener(this);
    Event.observe(this.domNode, "mouseover", this._mouseOverDomNodeListener);
    this._mouseOutDomNodeListener = this._onMouseOutDomNode.bindAsEventListener(this);
    Event.observe(this.domNode, "mouseout", this._mouseOutDomNodeListener);    
  },
  deinitialize: function($super){
    Event.stopObserving(this.domNode, "mouseout", this._mouseOutDomNodeListener);
    $super();
 },
  _onMouseOverDomNode: function (event) {
    if (this._mouseout == true) {
      this._mouseout = false;
      this.fire("mouseenter", {});
    }
  },
  _onMouseOutDomNode: function (event) {
    var mx = Event.pointerX(event);
    var my = Event.pointerY(event);
    
    var dims = this.domNode.getDimensions();
    var offs = this.domNode.cumulativeOffset();
    
    var x1 = offs.left;
    var y1 = offs.top;
    var x2 = x1 + dims.width;
    var y2 = y1 + dims.height;
    
    if ((mx <= x1)||(my <= y1)||(mx >= x2)||(my >= y2)) {
      this._mouseout = true;
      this.fire("mouseexit", {});  
    } 
  }
});